package com.itheima;

import cn.itcast.config.EnableUserAndRole;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest

@EnableUserAndRole
public class test {
    @Autowired
    private EmpMapper empMapper;

    @Test
    public void test1 () {
        // 查询姓名中包含“李”且薪资大于等于5000的员工的 id, name, phone, salary字段
        QueryWrapper<Emp> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name", "李");
        queryWrapper.ge("salary", 5000);
        queryWrapper.select("id", "name", "phone", "salary");

        List<Emp> emps = empMapper.selectList(queryWrapper);
        emps.forEach(System.out::println);
    }

    @Test
    public void test2 () {
        // 更新id为5, 6, 7的员工的薪水，加2000
        UpdateWrapper<Emp> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", 5, 6, 7);
        updateWrapper.setSql("salary = salary + 2000");
        empMapper.update(updateWrapper);
    }

    @Test
    public void test3 () {
        // 查询姓名中包含“李”且薪资大于等于5000的员工的 id, name, phone, salary字段
        LambdaQueryWrapper<Emp> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Emp::getName, "李")
                .ge(Emp::getSalary, 5000)
                .select(Emp::getId, Emp::getName, Emp::getPhone, Emp::getSalary);
        List<Emp> emps = empMapper.selectList(queryWrapper);
        emps.forEach(System.out::println);
    }

    @Test
    public void test4 () {
        // 更新id为5, 6, 7的员工的薪水，加2000
        LambdaUpdateWrapper<Emp> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.in(Emp::getId, 5, 6, 7);
        updateWrapper.setSql("salary = salary + 2000");
        empMapper.update(updateWrapper);
    }

}
